layui.config({
    base: CXL.ctxPath + '/externaljs/'
}).extend({ //设定组件别名
    echarts: 'echarts/echarts',
    axios: 'axios/axios',
    konva: 'konva/konva'
});
layui.use(['echarts','element', 'layer', 'carousel','konva'], function () {
    var element = layui.element;
    var $ = layui.$;
    var carousel = layui.carousel;
    // var echarts = layui.echarts;
    var konva = layui.konva;

    //点位信息量
    var cellMap = [];



    var canvas = document.getElementById("renderCanvas"); // 得到canvas对象的引用
    var engine = new BABYLON.Engine(canvas, true); // 初始化 BABYLON 3D engine

initPage();
    function initPage(){
        getCellMap();

    }



    // function createScene() {
    //
    //     // Create the scene space
    //     var scene = new BABYLON.Scene(engine);
    //
    //     // Add a camera to the scene and attach it to the canvas
    //     var camera = new BABYLON.ArcRotateCamera("Camera", 3 * Math.PI / 4, Math.PI / 4, 4, BABYLON.Vector3.Zero(), scene);
    //     camera.attachControl(canvas, true);
    //
    //     // Add lights to the scene
    //     var light1 = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(1, 1, 0), scene);
    //     var light2 = new BABYLON.PointLight("light2", new BABYLON.Vector3(0, 1, -1), scene);
    //
    //     // Add and manipulate meshes in the scene
    //     var box = BABYLON.MeshBuilder.CreateBox("box", {height: 1, width: 0.75, depth: 0.25}, scene);
    //
    //     return scene;
    //
    // };
    /******* Add the create scene function ******/
 function createScene() {

        // 创建一个场景scene
        var scene = new BABYLON.Scene(engine);
        var myGround = BABYLON.MeshBuilder.CreateGround("myGround", {width: 100, height: 100, subdivisions: 100}, scene);

        // 添加一个相机，并绑定鼠标事件
        var camera = new BABYLON.ArcRotateCamera("Camera", Math.PI / 2, Math.PI / 2, 2, new BABYLON.Vector3(0,0,5), scene);
        camera.attachControl(canvas, true);

        // 添加一组灯光到场景
        var light1 = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(1, 1, 0), scene);
        var light2 = new BABYLON.PointLight("light2", new BABYLON.Vector3(0, 1, -1), scene);
        var light3 = new BABYLON.PointLight("light2", new BABYLON.Vector3(0, -1, -1), scene);

        // 添加一个球体到场景中
        // 创建默认立方体
        // for (let item of cellMap) {
        //     console.log(item);
        //   item.box = BABYLON.MeshBuilder.CreateBox(item.name, {height: item.height/1000, width: 20, depth: 20}, scene);
        //   item.box.position = new BABYLON.Vector3(item.x/1000, item.y/1000, 0);
        // }
        var box =  BABYLON.MeshBuilder.CreateBox("myBox", {height: 50, width: 2, depth: 2}, scene);
        box.position = new BABYLON.Vector3(0, 30.5, 0);


// 设置长宽高并创建
//         var myBox = BABYLON.MeshBuilder.CreateBox("myBox", {height: 5, width: 5, depth: 5}, scene);

        return scene;
    };
    /******* End of the create scene function ******/


//获取所有的点
    function getCellMap() {
        $.ajax({
            url: '/boot/wms/cell/getCellMap',
            type: 'get',
            async: false,
            dataType: 'json',
            data:
                {
                    x1: 7400,
                    x2: 255000,
                    y1: 3200,
                    y2: 29200,

                },

            success: function (data) {
                cellMap = data.cellMap;

                console.log(cellMap);

                var scene = createScene(); //Call the createScene function

                // 最后一步调用engine的runRenderLoop方案，执行scene.render()，让我们的3d场景渲染起来
                engine.runRenderLoop(function () {
                    scene.render();
                });

                // 监听浏览器改变大小的事件，通过调用engine.resize()来自适应窗口大小
                window.addEventListener("resize", function () {
                    engine.resize();
                });

                // console.log(cellMap);
                // cellLocations = data.cellMap;

            }
        });
    }
});

